package com.tanhua.server.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.common.mapper.BlackListMapper;
import com.tanhua.common.pojo.BlackList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 小霞
 * @version 1.0
 * @description:
 * @date 2021/7/11 15:21
 */
@Service
public class BlackListService {

    @Autowired
    private BlackListMapper blackListMapper;

    public IPage<BlackList> queryBlacklist(Long userId, Integer page, Integer pageSize){
        QueryWrapper<BlackList> wrapper = new QueryWrapper<BlackList>();
        wrapper.eq("user_id",userId);
        //按照时间倒序
        wrapper.orderByDesc("created");

        Page<BlackList> pager = new Page<>(page,pageSize);
        return this.blackListMapper.selectPage(pager,wrapper);
    }

    /**
     * 移除黑名单
     *
     * @param id
     * @param blackId
     */
    public Boolean delBlacklist(Long id, Long blackId) {
        QueryWrapper<BlackList> wrapper = new QueryWrapper<BlackList>();
        wrapper.eq("user_id", id).eq("black_user_id", blackId);
        return this.blackListMapper.delete(wrapper) > 0;
    }
}
